package com.wql.crypto;

import java.util.zip.CRC32;

public class CRC32Utils {
	private CRC32Utils() {
	}

	public static String getValue(String data) {
		if (null != data)
			try {
				CRC32 crc32 = new CRC32();
				crc32.update(data.getBytes("utf-8"));
				return Long.toHexString(crc32.getValue());
			} catch (Exception e) {
			}
		return null;
	}

	public static boolean verify(String data, String md5) {
		if (null != data)
			return getValue(data).equals(md5);
		return false;
	}

	public static void main(String[] args) {
		String str = "hello world!";
		System.out.println(getValue(str));
		System.out.println(getValue(str+str+str+str));
		System.out.println(getValue(str).length());
	}
}
